import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * User: wenxiwen
 * Date: 2022/3/24
 * Time: 15:50
 * Description: No Description
 */
public class TestDemo {
    public static void main(String[] args) {
        int[][] array1 = {{1,2,3,4,},{4,5,6,7}};
        int[][] array2 = new int[2][3];
        for (int i = 0; i < array1.length; i++) {
            for (int j = 0; j < array1[i].length; j++) {
                System.out.print(array1[i][j]+ " ");
            }
            System.out.println();
        }
        System.out.println("foreach循环打印===================");
        for(int[] x : array1) {
            for(int y: x) {
                System.out.print(y + " ");
            }
            System.out.println();
        }
        System.out.println("方法深度打印===========================");
        System.out.println(Arrays.deepToString(array1));
    }
    public static void main5(String[] args) {
        int[] array = new int[10];
        Arrays.fill(array,0,5,5);
        System.out.println(Arrays.toString(array));
    }
    public static void main4(String[] args) {
        int[] array1 = {1,2,3,4,5,6,7,8,9};
        int[] array2 = {1,2,3,4,5,6,7,8,9};
        boolean flg = Arrays.equals(array1,array2);//比较数组的大小
        if (flg) {
            System.out.println("相等");
        } else {
            System.out.println("不等");
        }
    }
    public static int index(int[] array, int n) {
        int left = 0;
        int right = array.length-1;
        while(left <= right) {
            int mid = (left + right) / 2;
            if(array[mid] < n) {
                left = mid + 1;
            }else if(array[mid] > n) {
                right = mid - 1;
            } else {
                return mid;
            }
        }
        return -1;
    }
    public static void Swap(int[] array) {
        for (int i = 0; i < array.length - 1; i++) {
            boolean flg = true;
            for (int j = 0; j < array.length - 1 - i; j++) {
                if(array[j] > array[j+1]) {
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flg = false;
                }
            }
            if(flg) {
                break;
            }
        }
    }
    public static void main3(String[] args) {
        int[] array1 = {1,2,3,4,5,6,7,8,9};
        int[] array2 = {7,8,10,1,2,5,4,6,3};
        //Swap(array2);
        Arrays.sort(array2);
        int ret = Arrays.binarySearch(array2,5);
        //int ret= index(array2,3);
        if(ret < 0) {
            System.out.println("没有找到");
        } else {
            System.out.println("找到了这个数的下标是:" + ret);
        }
    }
 public static void main1(String[] args) {
     int[] array = {1,2,3,4,5,6,7};
     int[] ret = Arrays.copyOfRange(array,0,7);//下标是前闭后开的形式
     System.out.println(Arrays.toString(ret));
 }
}